﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;

namespace SEO.CControl
{
    public partial class DataGridViewPlus : DataGridView
    {
        public DataGridViewPlus()
        {
            InitializeComponent();
        }

        public DataGridViewPlus(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }

        /// 
        /// This prevents the "red X" error which happens when you cause updates to a datagrid
        /// from multiple threads.  It catches the OnPaint() exception and invalidates
        /// the grid so it gets redrawn the next time the application hits its message loop.
        ///
        /// The following solution to this problem was found
        /// at http://social.msdn.microsoft.com/forums/en-US/winforms/thread/fdd94896-80e9-4e91-9ed5-0348bf2633a9
        ///
        protected override void OnPaint(PaintEventArgs e)
        {
            try
            {
                base.OnPaint(e);
            }
            catch
            {
                Invalidate();
            }
        }
    }
}
